<template>
  <div class="min-h-screen bg-gray-100 flex flex-col">
    <!-- Header部分 -->
    <header class="w-full h-50px bg-[#0097FF] flex items-center justify-center fixed top-0 z-10">
      <p class="text-white text-18px font-medium">用户登陆</p>
    </header>

    <!-- 主要内容区域 -->
    <main class="flex-grow mt-50px mb-70px px-20px pt-30px">
      <!-- 表单部分 -->
      <div class="form-box bg-white rounded-10px shadow-md px-15px py-20px mb-20px">
        <div class="form-item flex items-center mb-20px pb-10px border-b border-gray-200">
          <div class="form-label flex-[0_0_80px] text-right pr-12px text-16px text-gray-700">手机号码：</div>
          <div class="flex-1">
            <input
                v-model="phone"
                type="tel"
                placeholder="手机号码"
                class="form-input w-full"
            >
          </div>
        </div>
        <div class="form-item flex items-center mb-20px pb-10px border-b border-gray-200">
          <div class="form-label flex-[0_0_80px] text-right pr-12px text-16px text-gray-700">密码：</div>
          <div class="flex-1">
            <input
                v-model="password"
                type="password"
                placeholder="密码"
                class="form-input w-full"
            >
          </div>
        </div>
      </div>

      <!-- 按钮区域 -->
      <div class="button-login mb-15px">
        <button
            @click="handleLogin"
            class="w-full h-45px bg-[#38CA73] text-white text-16px font-bold rounded-10px border-none outline-none active:opacity-90 transition-all"
        >
          登陆
        </button>
      </div>
      <div class="button-register">
        <button
            @click="goToRegister"
            class="w-full h-45px border border-gray-300 text-gray-700 text-16px font-bold rounded-10px bg-white active:bg-gray-100 transition-all"
        >
          去注册
        </button>
      </div>
    </main>

    <!-- 底部菜单部分 -->
    <FooterNav />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import FooterNav from '@/components/FooterNav.vue';

const router = useRouter();

const phone = ref('');
const password = ref('');

const handleLogin = () => {
  if (!phone.value) {
    alert('请输入手机号码');
    return;
  }
  if (!/^1\d{10}$/.test(phone.value)) {
    alert('请输入正确的手机号码');
    return;
  }
  if (!password.value) {
    alert('请输入密码');
    return;
  }

  alert('登录成功！');
  router.push('/');
};

const goToRegister = () => {
  router.push('/register');
};


</script>

<style scoped>
/* 自定义输入框样式 */
.form-input {
  height: 40px;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 0 12px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.form-input:focus {
  border-color: #1e9bff;
  box-shadow: 0 0 0 2px rgba(30, 155, 255, 0.2);
}

/* 输入框占位符样式 */
.form-input::placeholder {
  color: #ccc;
  font-size: 14px;
}

/* 标签样式 */
.form-label {
  flex: 0 0 80px;
  text-align: right;
  padding-right: 12px;
  font-size: 16px;
}
</style>